<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePayOrderTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('pay_order', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('sn')->comment('商户订单号');
            $table->string('pay_sn')->nullable()->comment('支付平台订单号');
            $table->bigInteger('user_id')->comment('用户ID');
            $table->bigInteger('order_id')->comment('业务订单ID');
            $table->decimal('price', 10, 2)->comment('金额');
            $table->tinyInteger('type')->comment('类型 1-预付款 2-取消责任费 3-服务结束补款');
            $table->tinyInteger('status', false, true)->comment('状态 0-未支付 1-已支付');
            $table->tinyInteger('pay_type', false, true)->nullable()->comment('支付方式 1-微信');
            $table->text('pay_data')->nullable()->comment('支付回调返回数据');
            $table->integer('success_time', false, true)->nullable()->comment('支付成功时间 时间戳');
            $table->timestamps();

            $table->index(['user_id', 'order_id']);
        });
        \DB::statement("ALTER TABLE `pay_order` comment '支付订单表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('pay_order');
    }
}
